﻿// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ngCordova', "ngTouch", 'starter.controllers', 'starter.services', 'elastichat'])

    .run(function ($ionicPlatform) {
        $ionicPlatform.ready(function () {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);
            }
            if (window.StatusBar) {
                // org.apache.cordova.statusbar required
                StatusBar.styleLightContent();
            }
        });
    })

    .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

        // Ionic uses AngularUI Router which uses the concept of states
        // Learn more here: https://github.com/angular-ui/ui-router
        // Set up the various states which the app can be in.
        // Each state's controller can be found in controllers.js

        $ionicConfigProvider.tabs.position("bottom"); //Places them at the bottom for all OS
        $ionicConfigProvider.tabs.style("standard"); //Makes them all look the same across all OS
        $ionicConfigProvider.navBar.alignTitle('center');
        $ionicConfigProvider.navBar.positionPrimaryButtons('left');
        $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
        $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');
        $stateProvider

            // setup an abstract state for the tabs directive
            .state('tab', {
                url: '/tab',
                abstract: true,
                templateUrl: 'templates/tabs.html',
                controller: 'TabCtrl'
            })

            // 产品列表页

            .state('tab.dash', {
                url: '/dash',
                views: {
                    'tab-dash': {
                        templateUrl: 'templates/tab-dash.html',
                        controller: 'DashCtrl'
                    }
                }
            })
            //众筹产品详情页
            .state('product-zc-detail', {
                url: '/product-zc-detail/:id',
                templateUrl: 'templates/product-zc-detail.html',
                controller: 'zcDetailCtrl'
            })
            // 聚募众筹投资页面
            .state('wmp-invest', {
                url: '/wmp-invest/:id',
                templateUrl: 'templates/wmp-invest.html',
                controller: 'wmpInvestCtrl'
            })

            .state('tab.chats', {
                url: '/chats',
                views: {
                    'tab-chats': {
                        templateUrl: 'templates/tab-chats.html',
                        controller: 'ChatsCtrl'
                    }
                }
            })
            .state('tab.chat-detail', {
                url: '/chats/:chatId',
                views: {
                    'tab-chats': {
                        templateUrl: 'templates/chat-detail.html',
                        controller: 'ChatDetailCtrl'
                    }
                }
            })
            .state('tab.account', {
                url: '/account',
                views: {
                    'tab-account': {
                        templateUrl: 'templates/tab-account.html',
                        controller: 'AccountCtrl'
                    }
                }
            })
            //我的资产
            .state('tab.myproperty', {
                url: '/myproperty',
                views: {
                    'tab-account': {
                        templateUrl: 'templates/tab-account_myproperty.html',
                        controller: 'PropertyCtrl'
                    }
                }

            })
            //我的收益
            .state('myearnings', {
                url: '/myearnings',
                templateUrl: 'templates/tab-account_myearnings.html',
                controller: 'EarningsCtrl'
            })

            .state('tab.entrust', {
                url: '/entrust',
                views: {
                    'tab-entrust': {
                        templateUrl: 'templates/tab-entrust.html',
                        controller: 'EntrustCtrl'
                    }
                }
            })

            .state('tab.choice', {
                url: '/choice',
                views: {
                    'tab-choice': {
                        templateUrl: 'templates/tab-choice.html',
                        controller: 'ChoiceCtrl'
                    }
                }
            })
            .state('tab.detail', {
                url: '/detail',
                views: {
                    'tab-dash': {
                        templateUrl: 'templates/tab-product-detail.html',
                        controller: "ProductDetailCtrl"
                    }
                }
            })
            .state('buynote', {
                url: '/buynote',
                templateUrl: 'templates/tab-buy-note.html',
                controller: 'ChoiceCtrl'
            })
            .state('rank', {
                url: '/rank',
                templateUrl: 'templates/tab-rank.html',
                controller: 'ChoiceCtrl'
            })
            .state('login', {
                url: "/login",
                    templateUrl: "templates/login.html",
                    controller: 'LoginCtrl'

            })
            .state('tab.charge', {
                url: '/charge',
                views: {
                    'tab-account': {
                        templateUrl: 'templates/charge.html',
                        controller: 'ChargeCtrl'
                    }
                }
            })
            .state('tab.withdraw', {
                url: '/withdraw',
                views: {
                    'tab-account': {
                        templateUrl: 'templates/withdraw.html',
                        controller: 'WithdrawCtrl'
                    }
                }
            })
            //选择支付银行卡
            .state('select-pay-bankcard', {
                url: '/select-pay-bankcard',
                // views:{
                //   'tab-dash':{
                // 	  templateUrl:'templates/select-pay-bankcard.html',
                // 	  controller:'SelectPayBankCardCtrl'
                //   }
                // }
                templateUrl: 'templates/select-pay-bankcard.html',
                controller: 'SelectPayBankCardCtrl'
            })
            .state('chargebanklist', {
                url: '/chargebanklist',
                cache: false,
                templateUrl: 'templates/charge-bank-list.html',
                controller: 'BankListChooseCtrl'
            })
            .state('accountverification', {
                url: '/accountverification',
                templateUrl: 'templates/account_info_verify.html',
                controller: 'AccVerifyCtrl'
            })
            .state('readytopay', {
                url: '/readytopay',
                templateUrl: 'templates/ready-to-pay.html',
                controller: 'ReadyToPayCtrl'
            })

            .state('identifier-bind', {
                url: '/identifier-bind',
                templateUrl: 'templates/identifier-bind.html',
                controller: 'identifierBindCtrl'
            })

            // 聚募投资页面
            .state('tab.buy-product', {
                url: '/buy-product/:id:type',
                views: {
                    'tab-dash': {
                        templateUrl: 'templates/buy-product.html',
                        controller: "wmpInvestCtrl"
                    }
                }
            })
            .state('signup', {
                url: "/signup",
                templateUrl: "templates/signup.html",
                controller: 'SignupCtrl'
            })
            .state('tab.bill', {
                url: '/bill',
                views: {
                    'tab-account': {
                        templateUrl: 'templates/bill.html',
                        controller: 'BillCtrl'
                    }
                }
            })
        // if none of the above states are matched, use this as the fallback
        $urlRouterProvider.otherwise('/tab/dash');

    })
// 旧接口
    .constant('mySettings', {
        appVersion: '1.0.13',

        apiSyncVersion: 'mobile/System/sync_version',

        apiGetAboutMeInfo: 'mobile/System/get_about_me',

        apiUriLogin: 'mobile/Login/login',

        apiUriRegister: 'mobile/Login/register',
        apiUriAuthCodeRegister: 'mobile/Login/auth_code_register',
        apiUriAuthCodeCheck: 'mobile/Login/auth_code_check',

        apiUriRecover: 'Mobile/Login/password_recover',
        apiUriReset: 'Mobile/Login/password_reset',
        apiUriAuthCodeRecover: 'Mobile/Login/auth_code_recover',

        apiUriPersonalSetting: 'mobile/Account/personal_setting',
        apiUriChangeNickName: 'Mobile/Account/change_nick_name',
        apiUriAnonymousToken: 'Mobile/Login/get_token',

        apiUriQueryBankCards: "mobile/bankcard/get_card_list",
        apiUriAddBankCard: "mobile/bankcard/create_new_card",
        apiUriRemoveBankCard: "mobile/bankcard/delete_card",
        apiUriSetDefaultBankCard: "mobile/bankcard/set_default_card",
        apiUriIdentifierBind: "mobile/account/identifier_bind",
        apiUriGetInviteLink: "mobile/account/get_inviter_url",
        apiUriGetInviteList: "mobile/account/get_invited_list",
        apiUriGetSecurityCodeByBankCardId: 'mobile/Account/request_security_code_by_cardid',
        apiUriGetSecurityCode: 'mobile/Account/request_security_code_url',

        apiUriCharge: 'mobile/Account/charge',
        apiUriChargeBeiFu: 'mobile/Account/chargeBeifu',
        apiUriGetUserWithdrawInfo: 'Mobile/Account/get_user_withdraw_info',
        apiUriUserWithdraw: 'Mobile/Account/user_withdraw',
        apiUriQueryUserAmount: 'Mobile/Account/query_user_amount',
        apiUriQueryUserBills: 'Mobile/Account/query_user_bills',
        apiUriPayByUserAccount: 'Mobile/Account/pay_funding_by_useramount',
        apiUriFundingGetProfit: 'Mobile/Account/funding_get_profit',
        apiUriGetLendingProduct: 'Mobile/Product/lending_detail',
        apiUriQueryEntrustsByUserId: 'Mobile/Entrust/query_entrusts_by_userid',
        apiUriAddEntrustMessage: 'Mobile/Entrust/add_entrust_message',
        apiUriAddProductOrder: 'Mobile/Account/add_product_order',
        apiUserAsses: 'Mobile/Account/get_amount_assets',
        apiUriGetFinancingDetail: 'api/Financing/get_financingDetail'
    })

// 新接口
    .constant('apiSettings', {
        appVersion: '1.0.13',
        NapiUriGetToken: "api/Login/get_token",
        NapiUriLogin: "api/Login/login",
        apiUriProjectInvest: "api/Dreammove/project_invest",
        apiUriGetWMPList: "api/Dreammove/project_zclist",
        //首页产品列表获取
        apiUriGetProductList: "api/Dreammove/product_basicInfo_list",
        apiUriGetWMPDetail: "api/Dreammove/project_zcdetail"

    })
    .filter('dateFilter', function () {
        return function (date) {
            return formatDate(new Date(date));
        }
    });
function formatDate(date, format) {

    if (!date)
        return;
    if (!format)
        format = "yyyy-MM-dd HH:mm:ss";
    switch (typeof date) {
        case "string":
            date = new Date(date.replace(/-/, "/"));
            break;
        case "number":
            date = new Date(date);
            break;
    }
    if (!date instanceof Date)
        return;
    var dict = {
        "yyyy": date.getFullYear(),
        "M": date.getMonth() + 1,
        "d": date.getDate(),
        "H": date.getHours(),
        "m": date.getMinutes(),
        "s": date.getSeconds(),
        "MM": ("" + (date.getMonth() + 101)).substr(1),
        "dd": ("" + (date.getDate() + 100)).substr(1),
        "HH": ("" + (date.getHours() + 100)).substr(1),
        "mm": ("" + (date.getMinutes() + 100)).substr(1),
        "ss": ("" + (date.getSeconds() + 100)).substr(1)
    };
    return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
        return dict[arguments[0]];
    });
}
